package com.panda.delivery.activity;

import android.content.Intent;
import android.os.Bundle;

import com.panda.delivery.MainApplication;
import com.panda.delivery.R;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactInstanceManager;
import com.microsoft.codepush.react.CodePush;
import com.panda.delivery.service.RecordNotificationService;

import org.devio.rn.splashscreen.SplashScreen;
import org.greenrobot.eventbus.EventBus;


import qiu.niorgai.StatusBarCompat;

import static qiu.niorgai.StatusBarCompat.changeToLightStatusBar;

public class MainActivity extends ReactActivity {
    private ReactInstanceManager mReactInstanceManager;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this, R.style.SplashScreenTheme);
        super.onCreate(savedInstanceState);
        AndroidBug5497Workaround.assistActivity(this);
        setStatusBar();
        mReactInstanceManager = MainApplication.getInstance().getReactNativeHost().getReactInstanceManager();
        CodePush.setReactInstanceHolder(() -> mReactInstanceManager);

        Intent intent = new Intent(this, RecordNotificationService.class);
        startService(intent);
    }

    @Override
    protected void onStart() {
        super.onStart();
//        setStatusBar();
    }

    protected void setStatusBar() {
        //设置状态栏颜色
//        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.white));
//        StatusBarCompat.changeToLightStatusBar(this);

        //translucent status bar 透明状态栏
        StatusBarCompat.translucentStatusBar(this, true);
//        should hide status bar background (default black background) when SDK >= 21

        //SDK >= 23, 将状态栏改为浅色模式(状态栏 icon 和字体会变成深色)
        changeToLightStatusBar(this);
    }

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "DeliveryApp";
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        CodePush.setReactInstanceHolder(null);
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
//        stopService(intent);
    }

}
